<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>内容管理</title>
<%@include file="/WEB-INF/jsps/header.jsp"%>
<script type="text/javascript">
	$("document").ready(function() {
		//刷新按钮
		$("#refrsh_btn").click(function() {
			$('#tt').tree("reload");
		});

		$('#tt').tree({
			onClick : function(node) {
				loadArticleList(node);
			}
		});
	});

	function loadArticleList(node) {
		$("#content").html(
				"<table id='dataList' title='"+node.text+"'></table>");//清空content
		$("#dataList").datagrid(
				{
					url : "${admin_base}/content/getArticleList.at?channelPid="	+ node.id,
					singleSelect : true,
					fitColumns : true,
					nowrap : false,
					pagination:true,
					height:getHeight(0.95),
					pageSize:20,
					idField : 'contentId',
					columns : [ [ {
						field : 'contentId',
						title : '编号',
						width : 30,
						align : "center"
					}, {
						field : 'title',
						title : '标题',
						width : 250,
						align : "left"
					}, {
						field : 'titleImg',
						title : '标题图片',
						width : 250,
						align : "left"
					}, {
						field : 'releaseDate',
						title : '发布日期',
						width : 50,
						align : "center"
					} ] ],
					toolbar : [ {
						text : '发表文章',
						iconCls : 'icon-add',
						handler : add
					}, {
						text : '修改',
						iconCls : 'icon-edit',
						handler : edit
					}, {
						text : '删除',
						iconCls : 'icon-remove',
						handler : del
					} ]
				});
	}

	function add() {
		var node = $('#tt').tree("getSelected");
		if(node.id==-1){
			parent.alert("不能在根节点下发表文章，请选择一个栏目");
			return;
		}
		var url = "${admin_base}/content/add.at?channelPid=" + node.id;
		parent.updateTab("发表文章", url, "161");
	}
	
	function alertEmptyRec(row){
		if(!row){
			$.messager.show({
                title:'提示',
                msg:'请选择一条记录',
                timeout:2000,
                showType:'slide'
            });
			return false;
		}
		return true;
	}
	
	function edit() {
		var row = $('#dataList').datagrid('getSelected');
		if(alertEmptyRec(row)){
			var url = "${admin_base}/content/edit.at?contentId=" + row.contentId;
			parent.updateTab("发表文章", url, "161");	
		}
	}
	function del() {
		parent.$.messager.confirm("提示","确定要删除吗？",function(r){
			var row = $('#dataList').datagrid('getSelected');
			if(alertEmptyRec(row)){
				goAjax({
					url:"${admin_base}/content/del.at?contentId=" + row.contentId,
					callback:function(json){
						$.messager.alert('提示','删除成功','info',function(){
							reload();
						});
					}
				});		
			}
		});
	}
	
	function reload(){
		$("#dataList").datagrid("reload");
	}
</script>
</head>
<body class="easyui-layout">

	<div region="west" border="true" title="栏目树" collapsible="false"
		style="width: 210px;">
		<div class="easyui-panel" style="padding: 5px;">
			<a href="#" class="easyui-linkbutton"
				data-options="plain:true,iconCls:'icon-reload'" id="refrsh_btn"
				style="width: 80px">刷新</a>
		</div>
		<ul id="tt" class="easyui-tree" url="${admin_base }/channel/tree.at"></ul>
	</div>

	<div region="center" title="文章列表" iconCls="icon-edit">
		<div id="content" style="width: 98%"></div>
		<div id="dlg"></div>
	</div>

</body>
</html>